package lab.ssl;

import java.io.InputStream;

import javax.net.ssl.SSLContext;
import javax.net.ssl.SSLServerSocket;
import javax.net.ssl.SSLSocket;

import cn.flant.ssl.SSLHelper;

public class SSLServer {
	public static void main(String[] args) throws Exception {
		SSLContext sslCtx = SSLHelper.initSSLContext(SSLInfo.KEY_FILE, null);
		SSLServerSocket server = (SSLServerSocket) sslCtx.getServerSocketFactory().createServerSocket(10001);
		System.out.println("Listen port: " + 10001);
		SSLSocket socket = (SSLSocket) server.accept();
		System.out.println("Accept client: " + socket.getRemoteSocketAddress());
		InputStream input = socket.getInputStream();
		byte[] buf = new byte[1024];
		int length = -1;
		while ((length = input.read(buf)) >= 0) {
			System.out.println(new String(buf, 0, length));
		}
	}
}
